import java.util.Scanner;

public class Answer1 {
    // fib数列
    //https://www.nowcoder.com/practice/18ecd0ecf5ef4fe9ba3f17f8d00d2d66?tpId=122&tqId=33668&ru=/exam/oj
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();

        int a=0,b=1,c=1;
        while(c<n){
            a=b;
            b=c;
            c=a+b;
        }
        int k=n-b;
        int l=c-n;
        if(k>l){
            System.out.println(l);
        }else{
            System.out.println(k);
        }

    }
}
